<template>
    <div>
      <!-- 面包屑导航 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '#' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>商品详情信息</el-breadcrumb-item>
      </el-breadcrumb>
      <div style="margin: 20px 0;" v-if="product!=null">
      <el-descriptions class="margin-top" :column="1" label-width="120px" border title="" :loading="loading">
        <el-descriptions-item label="商品名称" >{{ product.name }}</el-descriptions-item>
        <el-descriptions-item label="类别" >{{ product.categoryBean.name }}</el-descriptions-item>
        <el-descriptions-item label="简述">{{ product.subTitle }}</el-descriptions-item>
        <el-descriptions-item label="价格">{{ product.price }}</el-descriptions-item>
        <el-descriptions-item label="折扣">{{ product.discount }}</el-descriptions-item>
        <el-descriptions-item label="库存">{{ product.quantity }}</el-descriptions-item>
        <el-descriptions-item label="浏览量">{{ product.viewCount }}</el-descriptions-item>
        <el-descriptions-item label="销量">{{ product.saleCount }}</el-descriptions-item>
        <el-descriptions-item label="标签">
          <div>
            <el-tag  type="primary" v-for="(tagItem,index) in product.tagList" :key="index" style="margin-right: 4px;">{{ tagItem }}</el-tag>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="详细描述">
          <div v-html="product.describ" class="introduction"></div>
        </el-descriptions-item>
        <el-descriptions-item label="状态">
          <el-tag  type="success" v-if="product.status==1">正常</el-tag>
          <el-tag  type="info" v-if="product.status==-1">已下架</el-tag>
        </el-descriptions-item>
      </el-descriptions>
      <div class="info-pic">
        <p>商品主图：</p>
        <ul class="img-list">
          <li class="img-li" v-if="product.mainPic">
            <img :src="product.mainPic" class="avatar" />
          </li>
          <li class="img-li" v-else>
            未上传
          </li>
        </ul>
        <p>展示图：</p>
        <ul class="img-list">
          <li v-for="(pic,i) in product.picList" :key="i" class="img-li">
            <img :src="pic" class="avatar" />
          </li>
        </ul>
      </div>
    </div>
    <div class="show-btn">
      <el-button icon="Back" @click="goBack">返回</el-button>
    </div>
  </div>
</template>
<script setup lang="ts">
  import { ref, reactive, nextTick, toRef } from "vue";
  import baseService from "@/service/baseService";
  import { ElMessage, ElMessageBox } from "element-plus";
  import { timestampToDayHM, timestampToHM } from "@/utils/utils"
  import { fileUploader } from '@/utils/upload.js'
  import { useRouter, useRoute } from 'vue-router';
  
  // 查询参数
  const queryForm = reactive({
    deptName: "",
    pageNo: 1,
    pageSize: 10
  });
  const router = useRouter();
  const route = useRoute();
  // 列表内容数量
  const total = ref(0);
  // 列表是否加载
  const loading = ref(true);
  // 列表返回值
  const list = ref<any[]>([]);
  
  // 表单实例
  const formRef = ref();
  // 是否打开弹出框
  const open = ref(false);
  const openDetail = ref(false);
  // 弹出框标题
  const title = ref("");
  const product = ref();
  const shopId = ref();

  // 表单验证
  const rules = ref({
    deptName: [{ required: true, message: "规则名称不能为空", trigger: "blur" }],
  });

  function goBack(){
    router.back()
  }

  const getInfo = () => {
    const infoId = route.query.pid
    console.log('从路由获取参数：', route.query)
    shopId.value = infoId
    loading.value = true;
    baseService.get(`/admin/product/info/${infoId}`).then((res) => {
      console.log('获取商品信息：',res)
      product.value = res.data
      loading.value = false;
    }).catch(() => {
      loading.value = false;
    });
  }
  
  getInfo();
</script>
  
<style scoped>
.avatar-uploader :deep() .el-upload {
    border-radius: 6px;
    background-color: #fff;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    width: 100%;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #41a8a8;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    border: 1px dashed #8c939d;
    width: 220px;
    height: 160px;
    line-height: 160px;
    text-align: center;
  }
  .showUploader :deep() .el-upload-list{
    display: none;
  }
  .avatar {
    width: 220px;
    height: 160px;
    display: block;
  }
  .img-list{
    width: 100%;
    display: flex;
    flex-wrap: wrap;
  }
  .img-list .img-li{
    display: inline-block;
    margin-right: 1%;
    width: 25%;
    margin-bottom: 5px;
  }
  .demo-image{
    margin-top: 15px;
  }
  .quill-editor {
    height: 250px;
    margin-bottom: 100px;
  }
  .el-upload{
    width: 100%;
  }
  .logo-remove{
    font-size: 22px;
    position: absolute;
    top: 10px;
    right: 10px;
    color: #fff;
    text-shadow: gray 4px 4px 5px;
  }
  .logo-remove:HOVER{
    color: #F56C6C;
  }
  .info-pic{
    width: 80%;
    margin: 35px auto;
  }
.introduction{
    white-space: pre-line;
  }
.show-btn{
  margin: 15px auto;
  text-align: center;
}
.img-list .img-li{
  width: 260px;
  position: relative;
  margin-right: 10px;
}
.logo-remove{
  font-size: 22px;
  position: absolute;
  top: 10px;
  right: 10px;
  color: #f00;
  cursor: pointer;
  text-shadow: #000 4px 4px 5px;
}
.logo-remove .el-icon{
  box-shadow: #fff 3px 5px 6px;
  background-color: #fff;
}
.logo-remove:HOVER{
  color: #F56C6C;
}
</style>
  